﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml">   
<head>   
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />   
<title>无标题文档</title>   
</head>   
<body>
<?php
require "include.php";
?>

<!--相关操作-->
<div align="right">
<a href="input_excel.html">导入excel<<<</a><br>
    <?php
    if(isset($_GET['type'])){
        echo "<a href='output.php?type={$_GET['type']}'>".'导出excel>>>'.'</a>'.'<br>';
        echo "<a href='input_word.php?type={$_GET['type']}'>".'添加信息'.'</a>'.'<br>';
        echo "<a href='api.php?act=form_del&type={$_GET['type']}'>".'删除这张表'.'</a>'.'<br>';
    }
    ?>
</div>
<!--展示目前数据库拥有的表-->
<div align="left">
    <?php
    $rs = new DBHelper();
    $sql = 'select * from type';
    $res = $rs->fetch_all($sql);
    if(mysqli_num_rows($res) > 0) {
        while ($row = mysqli_fetch_array($res)) {
            echo "<a href='index.php?type={$row['type']}'>".$row['type'].'</a>'.'<br>';
        }
    }
    ?>
</div>
<!--所点击表的详情-->
<div align="center">
<?php
require "include.php";
$rs = new DBHelper();
if(!isset($_GET['type'])){
    echo '<h1>'."请选择左侧一张表".'</h1>';
}else{
    $rs = new DBHelper();
    $sql = "select * from type where type='{$_GET['type']}'";
    $result = $rs->query_one($sql);
    if($result!=null){
        $res = $rs->fetch_all("SHOW COLUMNS FROM `{$_GET['type']}`");
        $sql = "select * from {$_GET['type']}";
        $result = $rs->fetch_all($sql);
        $rt = array();
        if ($res instanceof mysqli_result)
        {
            while (($row = $res->fetch_assoc()) != FALSE)
            {
                $row['CanBeNull'] = $row['Null'] === 'YES';   //字段值是否可以为空，是的话值为'YES'
                $rt[] = $row;
            }
        }
        $ss=count($rt);
        echo '<h1>'.$_GET['type'].'</h1>';
        echo '<table border="1" cellpadding="0" cellspacing="0" width="80%" align="center" >';
        /*打印标题*/
        echo '<tr>';
        for ($i = 0; $i < $ss; $i++) {
            echo '<td>'.$rt[$i]['Field'].'</td>';
        }
        echo '<td>'."操作".'</td>';
        echo '<tr>';
        echo "</br>";
        /*打印内容*/
        while ($arr = mysqli_fetch_array($result)) {
            echo '<tr>';
            for ($i = 0; $i < $ss; $i++) {
                echo '<td>'.$arr[$i].'</td>';
            }
            echo "<td>"."<a href='api.php?act=delete&type={$_GET['type']}&id={$arr[0]}'>删除</a>/<a href='update.php?type={$_GET['type']}&id={$arr[0]}'>修改</a>"."</td>";
            echo '</tr>';
        }
        echo '</table>';
    }else{
        echo '<h1>'."此表已被删除".'</h1>';
    }
}
?>
</div>
</body>   
</html>